package com.wuxf.service;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wuxf.entity.UserInfo;
import com.wuxf.entity.custom.UserInfoCustom;
import com.wuxf.mapper.custom.UserCustomMapper;
import com.wuxf.util.DateUtils;

@Service
@SuppressWarnings({"rawtypes","unchecked"})
public class UserService {
	@Autowired
	private UserCustomMapper userCustomMapper;
	
	public List<UserInfoCustom> findByMap(HashMap paraMap) {
		return userCustomMapper.findByMap(paraMap);
	}
	
	
	public UserInfo findByAreaId(int areaId) {
		HashMap paraMap = new HashMap();
		paraMap.put("areaId", areaId);
		UserInfoCustom userInfoCustom = userCustomMapper.findByMap(paraMap).get(0);
		UserInfo userInfo = new UserInfo();
		BeanUtils.copyProperties(userInfoCustom, userInfo);
		return userInfo;
	}
	
	public UserInfo findByUserId(int userId) {
		HashMap paraMap = new HashMap();
		paraMap.put("userId", userId);
		UserInfoCustom userInfoCustom = userCustomMapper.findByMap(paraMap).get(0);
		UserInfo userInfo = new UserInfo();
		BeanUtils.copyProperties(userInfoCustom, userInfo);
		return userInfo;
	}
	
	
	public UserInfo updateUser(UserInfo userInfo) {
		userInfo.setUpdateTime(DateUtils.getNowDate());
		userCustomMapper.updateUser(userInfo);
		return userInfo;
	}
	
}
